<?php
use yii\helpers\Html;
use kartik\form\ActiveForm;
use kartik\select2\Select2;
use yii\helpers\Url;
use yii\web\JsExpression;

/* @var $this yii\web\View */
/* @var $model admin\modules\buildingOrder\models\forms\BuildingOrders */
/* @var $form \kartik\form\ActiveForm */

$js = <<<JS
$.fn.modal.Constructor.prototype.enforceFocus = function () {};
JS;
$this->registerJs($js);
?>

<div class="building-orders-form">

    <?php $form = ActiveForm::begin(); ?>

    <?= $form->field($model, 'title')->textInput() ?>

    <?= $form->field($model, 'status')->dropDownList($model::getStatusDesc()) ?>

    <?=$form->field($model, 'county_id')->widget(Select2::class, [
        'options' => ['placeholder' => '请选择...'],
        'pluginOptions' => [
            'placeholder' => '搜索 ...',
            'allowClear' => true,
            'ajax' => [
                'url' => Url::to(['/pub/ajax/area-sel', 'level' => 3]),
                'dataType' => 'json',
                'data' => new JsExpression('function(params) { return {q:params.term}; }')
            ],
            'escapeMarkup' => new JsExpression('function (markup) { return markup; }'),
            'templateResult' => new JsExpression('function(res) { return res.text; }'),
            'templateSelection' => new JsExpression('function (res) { return res.text; }'),
        ],
        'initValueText' => $model->county?$model->county->merger_name:"",
        'pluginEvents' => [
            'change' => 'function() { OrderExpressAdd.county_id = $(this).val(); }'
        ],
    ]) ?>

    <?= $form->field($model, 'address')->textarea(['maxlength' => true]) ?>

    <?= $form->field($model, 'custom_name')->textInput(['maxlength' => true]) ?>

    <?= $form->field($model, 'custom_mobile')->textInput(['maxlength' => true]) ?>

	<?php if (!Yii::$app->request->isAjax){ ?>
	  	<div class="form-group">
	        <?= Html::submitButton($model->isNewRecord ? Yii::t('app', '新建') : Yii::t('app', '更新'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
	    </div>
	<?php } ?>

    <?php ActiveForm::end(); ?>
    
</div>
